<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\AdminUser;
use yii\filters\VerbFilter;


/**
 * AdminUserSearch represents the model behind the search form about `backend\models\AdminUser`.
 */
class GoodsSearch extends Goods
{
    /**
     * @inheritdoc
     */
    public function behaviors ()
    {
        return [
            'verbs' => [
                'class'   => VerbFilter::className() ,
                'actions' => [
                    'delete' => [ 'POST' ] ,
                ] ,
            ] ,
        ];
    }

    public function rules()
    {
        return [
            [['name','project_name'], 'safe'],

        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {


        $query = goods::find()->alias('a')->select(['a.*','b.project_name'])->leftJoin('zj_project b','a.pid = b.id');



        // add conditions that should always apply here


        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name])
            ->andFilterWhere(['like', 'b.project_name', $this->project_name]);


        // grid filtering conditions
        return $dataProvider;
    }
}
